//
//  AllMessageViewController.m
//  NoneCar
//
//  Created by DongSen on 2018/7/11.
//  Copyright © 2018年 董森森. All rights reserved.
//

#import "BasicInformationViewController.h"
#import "APIManager+Messages.h"
#import "UIView+ViewController.h"
#import "PhotosViewController.h"
#import "MessageTableViewCell.h"
#import "AllMessageViewController.h"

@interface AllMessageViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,strong)NSMutableArray * dataArray;
@property(nonatomic,copy)NSString * showStrings;

@end

@implementation AllMessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.estimatedRowHeight = 60;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    [self.tableView registerNib:[UINib nibWithNibName:@"MessageTableViewCell" bundle:nil] forCellReuseIdentifier:@"MessageTableViewCell"];
    self.tableView.backgroundColor =BackGroundColor;
    self.blackView.frame = self.view.bounds;
    [self.tableView addSubview:self.blackView];
    [self.tableView reloadData];
    
    // Do any additional setup after loading the view from its nib.
}
- (void)netWork{
    WeakSelf(self);
    NSDictionary * pars = @{};
    [self showLoading];
    [[APIManager sharedNetManager] PostGetMessagesWithTypes:pars sucess:^(NSInteger code, NSDictionary *dict) {
        [weakSelf hidloading];
        if ([[dict objectForKey:@"Code"] integerValue]==1){
            
        }
        else{
            [weakSelf showMessage:[dict objectForKey:@"Message"]];
        }
    } failure:^(NSInteger code, NSError *error) {
        [weakSelf hidloading];
         [weakSelf showNetError];
    }];
}
-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self showLoading];
    NSLog(@"刷新了");
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        for (int i =0; i<50; i++) {
            self.showStrings = [NSString stringWithFormat:@"asda%@",self.showStrings];
            [self.dataArray addObject:self.showStrings];;
        }
        [self hidloading];
        if (self.dataArray.count) {
            self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        }
        [self.tableView reloadData];
    });
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 12;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (self.dataArray.count){
        [self.blackView removeFromSuperview];
    }
    else{
        [self.tableView bringSubviewToFront:self.blackView];
    }
    return self.dataArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MessageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"MessageTableViewCell"];
    cell.opinionLabel.text =[NSString stringWithFormat:@"%@",self.dataArray[indexPath.section]];
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    BasicInformationViewController * view = [BasicInformationViewController new];
    view.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:view animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
